home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.43 / 2.43.cs next >
Text File  |  2004-08-31  |  2KB  |  56 lines

  1. /* A day at the races. */
  2. using System;
  3.  
  4. namespace Chapter2 {
  5.     class Class1 {
  6.         static void Main() {
  7.             string input = "Y", Horse; 
  8.             int iNumber1 = 0, iNumber2 = 0, iNumber3 = 0;
  9.  
  10.             Console.WriteLine("Let's have a horse race.\n" 
  11.                 + "To play select one of the horses below");
  12.  
  13.             while (char.ToUpper(char.Parse(input)) != 'N') {
  14.                 Console.WriteLine("(1) for Whitefire\n"
  15.                     + "(2) for The Train and, \n"
  16.                     + "(3) for Noisy Glue\n");
  17.                 Horse = Console.ReadLine ();
  18.  
  19.                 TheRace(ref iNumber1);        
  20.                 TheRace(ref iNumber2);        
  21.                 TheRace(ref iNumber3);       
  22.  
  23.                 TieBreaker(iNumber1, ref iNumber2);  
  24.                 TieBreaker(iNumber2, ref iNumber3);  
  25.                 TieBreaker(iNumber1, ref iNumber3);  
  26.  
  27.                 Console.Write("And the winner is ");
  28.           
  29.                 if (iNumber1 > iNumber2 && iNumber1 > iNumber3)
  30.                     Console.WriteLine("Noisy Glue"); // 3 
  31.                 else if (iNumber2 > iNumber1 && iNumber2 > iNumber3)   
  32.                     Console.WriteLine("The Train"); // 2
  33.                 else 
  34.                     Console.WriteLine("Whitefire"); // 1
  35.  
  36.                 Console.WriteLine("Would you like to play again (Y/N)?");
  37.                 input = Console.ReadLine();  
  38.             }    
  39.         }                                              
  40.         
  41.         static void TheRace(ref int Num) {
  42.             Random rnd = new Random();
  43.  
  44.             Num = (int)Math.Round(rnd.NextDouble() * 1000);         
  45.         }
  46.     
  47.         static void TieBreaker(int Num1, ref int Num2) {
  48.             if (Num1 == Num2) {
  49.                 TheRace(ref Num2); 
  50.                 TieBreaker(Num1, ref Num2);
  51.             }  
  52.         } 
  53.     }
  54. }
  55.  
  56.